script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];

let color=0;
let oldx=0;
let phase=0;
let spin=0;
let enemyradius=160;
let enemyangle=270;
let movespeed=0;
let shootspeed=rand_int(0,360);

let character="Takeo";
let cutin=character;
let dispelled=0;
let spellcards=4;
let spellcardnumber=30;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=-30;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEcharge1=("\script\SoundEffects\charge1.wav");
let SEshots7=("\script\SoundEffects\shots7.wav");
let SEshotb6=("\script\SoundEffects\shotb6.wav");

let BG1=("\script\Images\BackgroundLayers\Takeo1a.png");
let GRboss=("\script\Images\CharacterSprites\Takeo.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsTakeo1.txt");

	LoadSE("\script\SoundEffects\charge1.wav");
	LoadSE("\script\SoundEffects\shots7.wav");
	LoadSE("\script\SoundEffects\shotb6.wav");

	LoadGraphic("\script\Images\CharacterSprites\Takeo.png");
	LoadGraphic("\script\Images\BackgroundLayers\Takeo1a.png");

	SetScore(300000);
	SetLife(300);
	SetTimer(52);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,cy-160,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(35,35,35,35);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; if(enemyradius>70){ damagerate=20; } }
if(GetCommonData("BombOn")==1){ damagerate=6; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Condensation [Humidity Control] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


oldx=GetX;

if(time>=60){
	if(movespeed<1.5){ movespeed+=0.03; }
	if(frame<360 && enemyradius<160){ enemyradius++; } //Increase radius from center
	if(frame>=360 && enemyradius>0){ enemyradius--; } //Go to center
	if(frame>=360 && enemyradius<0){ enemyradius=0; } //Stay in center
	if(frame==500){ phase++; } //Absorb
	if(frame>=500 && length(bullet1)<=0){ shootspeed=rand(0,360); color=0; frame=-30; phase++; } //Reset
	SetX(cx+enemyradius*cos(enemyangle));
	SetY(cy+enemyradius*sin(enemyangle));
if((phase+0)%4==0 || (phase+3)%4==0){ enemyangle+=movespeed; }
if((phase+2)%4==0 || (phase+1)%4==0){ enemyangle-=movespeed; }
movespeed=1+0.3*cos(time);
}

if(frame>=60 && frame<360 && time%10==0){

let speed=3.2+1.1*cos(shootspeed*2);
let angle=0;
if((phase+0)%4==0 || (phase+3)%4==0){ angle=-time*5; }
if((phase+2)%4==0 || (phase+1)%4==0){ angle=time*5; }

SetShotColor(255,255,255);
	loop(3){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,speed);
	ObjShot_SetBombResist(shot1,true);
	let random=rand_int(0,1);
		if(random==0){ ObjShot_SetGraphic(shot1,79); }
		if(random==1){ ObjShot_SetGraphic(shot1,78); }
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle+=360/3;
	}
PlaySE(SEshotb6);
}

if(phase%2!=0 && enemyradius<=0 && time%50==0 && time>=60){
let angle=rand(0,360);
SetShotColor(255-color,255-color,255-color);
	loop(60){
	CreateShot02(GetX,GetY,4+0.4*cos(angle*8),angle,-0.1,1.5,87,0);
	angle+=360/60;
	}
color+=20;
PlaySE(SEshots7);
usespell=20;
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i);
	i--;
	}
	else{
		if(phase%2==0){
		if(Obj_GetSpeed(bullet1[i])>0){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])-0.02); }
		if(Obj_GetSpeed(bullet1[i])<0){ Obj_SetSpeed(bullet1[i],0); }
		}

		if(frame==500){ Obj_SetSpeed(bullet1[i],0); }

		if(phase%2!=0 && enemyradius<=0){
		Obj_SetAngle(bullet1[i],atan2(GetY-Obj_GetY(bullet1[i]),GetX-Obj_GetX(bullet1[i])));
		if(Obj_GetSpeed(bullet1[i])<2){ Obj_SetSpeed(bullet1[i],Obj_GetSpeed(bullet1[i])+0.01); }
		if((((GetX-Obj_GetX(bullet1[i]))^2+(GetY-Obj_GetY(bullet1[i]))^2)^0.5)<10){ Obj_Delete(bullet1[i]); }
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(frame==0 && time>=60 && GetTimer>1){
	SetColor(0,100,255);
	Concentration01(60);
	SetColor(255,255,255);
PlaySE(SEcharge1);
}

shootspeed++;

time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";
}

@BackGround{
	if(bgfade<180){ bgfade+=5; }

	SetGraphicRect(0+80*cos(time),0,528+80*cos(time),592);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicRect(0,outfit,128,outfit+128);
	if((((oldx-GetX)^2+(cy-cy)^2)^0.5)>0.2){
	if(GetX<oldx){ SetGraphicRect(128,outfit,256,outfit+128); }
	if(GetX>oldx){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	SetShotColor(255,255,255);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}